package cn.demoxy.service.impl;

import cn.demoxy.mapper.DemoTenantMapper;
import cn.demoxy.model.dto.DemoTenantDTO;
import cn.demoxy.model.entity.DemoTenant;
import cn.demoxy.service.IDemoTenantService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @auther demo
 * @date 2022/5/17 11:26
 * 租户表业务实现
 */
@Service
public class DemoTenantServiceImpl extends ServiceImpl<DemoTenantMapper, DemoTenant> implements IDemoTenantService {

    @Override
    public Page<DemoTenant> findAllTenantByKeyword(DemoTenantDTO tenantDTO) {
        //创建page对象，传递当前页，每页记录数
        Page<DemoTenant> page = new Page<>(tenantDTO.getCurrent(), tenantDTO.getSize());
        //构建条件
        QueryWrapper<DemoTenant> wrapper = new QueryWrapper<>();
        //根据租户名称查询
        if (StringUtils.hasText(tenantDTO.getName())) {
            wrapper.like("name", tenantDTO.getName());
        }
        //根据租户状态查询
        if (StringUtils.hasText(tenantDTO.getStatus())) {
            wrapper.eq("status", tenantDTO.getStatus());
        }
        //调用方法实现分页查询
        Page<DemoTenant> tenantPages = baseMapper.selectPage(page, wrapper);
        //返回结果
        return tenantPages;
    }
}
